package com.gustuy.controller;

import com.alibaba.fastjson.JSON;
import com.gustuy.mapper.UserMapper;
import com.gustuy.pojo.User;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class Login {
    @RequestMapping("/gologin")
    public String goLogin(){
        return "login";
    }
    @RequestMapping("/goSignup")
    public String goSignup(){
        return "";
    }
    @RequestMapping("/login")
    public String loginIn(User user, @RequestParam("sex")String sex, Model model){
        ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("ApplicationContext.xml");
        UserMapper userMapperImpl = context.getBean("userMapperService", UserMapper.class);
        int back=userMapperImpl.addUser(user);
        if(sex.equals("Man")){
            user.setSex(User.Sex.Man);
        }else {
            user.setSex(User.Sex.Woman);
        }
        if(back>0){
            model.addAttribute("msg","注册成功");
        }
        else {
            model.addAttribute("msg","注册失败");
        }
        return "showmessage";
    }


}
